package com.diamond.smart.info.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.diamond.smart.info.entity.CityEntity;
import com.diamond.smart.info.service.CityService;
import com.diamond.common.utils.PageUtils;
import com.diamond.common.utils.R;


/**
 * @author SunKewei
 * @email skw777jo@163.com
 * @date 2022-04-26 16:02:20
 */
@RestController
@RequestMapping("info/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = cityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{cityId}")
    public R info(@PathVariable("cityId") Integer cityId) {
        CityEntity city = cityService.getById(cityId);

        return R.ok().put("city", city);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CityEntity city) {
        cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CityEntity city) {
        cityService.updateById(city);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] cityIds) {
        cityService.removeByIds(Arrays.asList(cityIds));

        return R.ok();
    }

}
